package com.example.core

import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

/**
 * Created by MajinBuu on 2021/2/7 0007.
 * @desc .
 */
abstract class BaseViewHolder : RecyclerView.ViewHolder {

    constructor(itemView: View) : super(itemView)

    private val viewHashMap = HashMap<Int, View>()

    fun <T : View> getView(id: Int): T {

        var view = viewHashMap.get(id)
        if (view == null) {
            view = itemView.findViewById(id)
            viewHashMap.put(id, view)
        }
        return view as T
    }

    fun setText(id: Int, text: String?) {
        getView<TextView>(id).text = text
    }
}